/*
 * @Author: csxjy
 * @LastEditors: csxjy
 * @Date: 2023-08-31 13:58:46
 * @LastEditTime: 2023-10-08 17:30:19
 * @FilePath: \dcp-user-center-admin-view\sh\cp.js
 * @Description:
 *
 * Copyright (c) 2023 by 天河数云/智能计算事业部, All Rights Reserved.
 */
const shell = require('shelljs')
const colors = require('colors-console')
const { name } = require('../package.json')
const { execSync } = require('child_process');

console.log(colors('green', `开始git-branch操作`));

function getGitBranch() {
  try {
    return execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim();
  } catch (e) {
    console.log(colors('red', `获取分支失败:${e.message}`))
    return null;
  }
}

const branch = getGitBranch()

let i = shell.mv(`./dist/${name}.zip`, `./dist/${name}.${branch}.zip`)

if (i.code !== 0) {
  console.log(colors('red', '更改zip包名失败', info.stderr))
}

shell.exec('sleep 1');

i = shell.mv(`./dist/${name}.tar.gz`, `./dist/${name}.${branch}.tar.gz`)

if (i.code !== 0) {
  console.log(colors('red', '更改tar.gz包名失败', info.stderr))
}


console.log(colors('green', `git-branch操作结束`));
